package com.gaojiawei.multiThread07_ThreeSpecialOrderliness;

/**
 * use volatile to ensure orderliness
 *
 * instruction rearrangement will happen in singleton pattern ,causing object to have only a merroy address and no property value ,in order to resolve this problem Using volatile keyword
 */
public class l02_ResolveOrderlinessWithVolatile {

    //user volatile keyword
    private static volatile l02_ResolveOrderlinessWithVolatile l02_resolveOrderlinessWithVolatile;

    private l02_ResolveOrderlinessWithVolatile (){};

    private static  l02_ResolveOrderlinessWithVolatile getInstance(){
        if(l02_resolveOrderlinessWithVolatile == null){
            synchronized (l02_ResolveOrderlinessWithVolatile.class){
                if(l02_resolveOrderlinessWithVolatile == null){
                    l02_resolveOrderlinessWithVolatile = new l02_ResolveOrderlinessWithVolatile();
                }
                return l02_resolveOrderlinessWithVolatile;
            }
        }
        return l02_resolveOrderlinessWithVolatile;
    }


}
